using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

namespace Yoozoo.Gameplay.City
{
    
    public class ShakeScreenCityCam : MonoBehaviour
    {
        public float distance;
        public float time;
        // 集装箱落下时震屏
        public void ShakeScreenCam()
        {
            var cameraObj = CityManager.Instance.mobileTouchCamera;
            if (cameraObj == null)
            {
                return;
            }
            var oriPos = cameraObj.transform.position;
            var focusAtByTimeTest = oriPos;
            var targetPos = new Vector3(focusAtByTimeTest.x, focusAtByTimeTest.y - distance, focusAtByTimeTest.z);
            DOTween.To(() => focusAtByTimeTest, p =>
                {
                    focusAtByTimeTest = p;
                }, targetPos, time).OnUpdate(() =>
                {
                    cameraObj.transform.position = focusAtByTimeTest;
                })
                .OnComplete((() =>
                {
                    DOTween.To(() => focusAtByTimeTest, p =>
                    {
                        focusAtByTimeTest = p;
                    }, oriPos, time).OnUpdate(() =>
                    {
                        cameraObj.transform.position = focusAtByTimeTest;
                    });
                }));
        }
    }
}
